package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ScreenPriceQuery;
import com.xingkeduo.pojo.table.ScreenPriceTable;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenxianda <chenxianda@xingkeduo.com>
 * @package BeautyOS 2019年7月19日 11:32:47
 * @copyright Copyright (c) XKD 2019
 */

@Component
public class ScreenPriceService {
    private static final String NAMESPACE = ScreenPriceTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ScreenPriceTable, ScreenPriceQuery> dao;

    //查询一条
    public ScreenPriceTable selectById(long id) throws Throwable {
        ScreenPriceTable screenPriceTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(screenPriceTable))
            return screenPriceTable;
        return null;
    }

    //查询多条
    public List<ScreenPriceTable> selectScreenPrices(ScreenPriceQuery screenPriceQuery) throws Throwable {
        List<ScreenPriceTable> screenPriceTableList = dao.select(NAMESPACE, screenPriceQuery);
        if (!CommonUtil.isEmpty(screenPriceTableList))
            return screenPriceTableList;
        return null;
    }

    //插入
    public int insert(ScreenPriceTable screenPriceTable) throws Throwable {
//        Long code = IdentityUtil.nextId(IdentityUtil.Worker.DEFAULT);
//        screenPriceTable.setCode(code);
        return dao.insert(NAMESPACE, screenPriceTable);
    }
    //批量插入
    public int insertAll(List<ScreenPriceTable> screenPriceList) throws Throwable {
//        shopsDaysTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, screenPriceList);
    }


    //更新
    public int update(ScreenPriceTable screenPriceTable) throws Throwable {
        return dao.update(NAMESPACE, screenPriceTable);
    }

    public int delete(ScreenPriceTable screenPriceTable) throws Throwable {
        return dao.update(NAMESPACE, screenPriceTable);
    }

    //批量
    public int updateRows(ScreenPriceTable screenPriceTable, ScreenPriceQuery screenPriceQuery) throws Throwable {
        return dao.update(NAMESPACE,screenPriceTable,screenPriceQuery);
    }

    //数量
    public int count(ScreenPriceQuery screenPriceQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, screenPriceQuery);
    }
}
